package com.anzia.stream;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;


/**
 *@ClassName ObjectOutputStream
 *@Description
 *@Author Anzia.
 *@Date 2021/4/9 14:31
 *@Version 1.0
 **/
public class ObjectOutputStream_Demo {

    public static void main(String[] args) throws Exception {

        //创建对象流
        FileOutputStream fos = new FileOutputStream("static\\stu.bin");
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        //序列化（写入操作）
        Student student = new Student("张三", 20);
        Student student1 = new Student("李四", 20);

        ArrayList<Student> list = new ArrayList<>();
        list.add(student);
        list.add(student1);

        oos.writeObject(list);

        //关闭
        oos.close();
        System.out.println("序列化完毕！");

    }

}
